<template>
  <!--会签管理-我的提交列表-劳务结算详情弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <j-form-container class="scroll-view" style="height: 600px">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="审批编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvNumber" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.approvNumber" placeholder="请输入介绍"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="提交时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="submitTime" style="margin-bottom: 10px;">
              <j-date v-model="model.submitTime" :showTime="true" :disabled="disabled" date-format="YYYY-MM-DD "
                style="width: 100%" placeholder="请选择提交时间"></j-date>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="发起人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userName" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.userName" placeholder="请输入发起人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="post" style="margin-bottom: 10px;">
              <a-select :disabled="disabled" placeholder="请选择职位" v-model="model.post">
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="depart" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" placeholder="请选择部门" v-model="model.departName">
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status" style="margin-bottom: 10px;">
              <a-select :disabled="disabled" placeholder="请选择状态" v-model="model.status">
                <a-select-option value="0">未提交</a-select-option>
                <a-select-option value="1">审核中</a-select-option>
                <a-select-option value="2">已同意</a-select-option>
                <a-select-option value="3">已驳回</a-select-option>
                <a-select-option value="4">已撤销</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.title" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName" style="margin-bottom: 10px;">
              <a-select :disabled="disabled" :options="levelOneOptions" placeholder="请选择项目" v-model="model.projectName">
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="班组" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierName" style="margin-bottom: 10px;">
              <a-select :disabled="disabled" placeholder="请选择班组" v-model="model.supplierName">
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractNumber" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.contractNumber" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="结算时间" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="period"
              style="margin-bottom: 10px;margin-left: 20px;">
              <div style="display: flex;align-items: center;">
                <a-input :disabled="disabled" style="width: 314px;margin: 0 52px 0 2px;" placeholder=""
                  v-model="model.period">
                </a-input>
                <j-date v-model="model.startTime" :showTime="true" :disabled="disabled" date-format="YYYY-MM-DD "
                  style="" placeholder="请选择开始时间"></j-date>
                <div style="width: 10px;margin: 0 10px;">~</div>
                <j-date v-model="model.endTime" :showTime="true" :disabled="disabled" date-format="YYYY-MM-DD" style=""
                  placeholder="请选择结束时间"></j-date>
              </div>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="结算项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settlementAccount" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.settlementAccount" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="本期完成量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentCompletion" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.currentCompletion" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="扣款或奖罚" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rewardAndPunish" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.rewardAndPunish" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="本期结算金额:" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="currentSettlementAmount" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" v-model="model.currentSettlementAmount" placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="累计结算金额:" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="accumulatedSettlementAmount" style="margin-bottom: 10px;">
              <a-input :disabled="disabled" style="" v-model="model.accumulatedSettlementAmount"
                placeholder=""></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
              style="margin-bottom: 10px;margin-left: 20px;">
              <textarea :disabled="disabled" v-model="model.remark" cols="100" rows="3" style="width: 93%;"></textarea>
            </a-form-model-item>
          </a-col>
          <a-row>
          </a-row>

          <a-row>
            <a-col :span="24">
              <a-form-model-item label="附件资料" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="attachment"
                style="margin:0 60px 10px 20px;">
                <j-upload v-model="model.attachment" :disabled="disabled" :buttonVisible="!disabled"></j-upload>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-row>

        <a-row>
          <a-form-model-item label="审核流程" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
            style="margin-bottom: 10px;margin-left: 20px;">
            <div style="display: flex;flex-direction: column;width: 100%;">
              <block v-for="(item, index) in list" :key="index">
                <div style="display: flex;flex-direction: column;">
                  <div style="display: flex;align-items: center;">
                    <div style="width:60px;margin-right: 5px;">审批人{{index + 1 }} </div>
                    <div
                      style="border: 0.5px solid gray; width: 674px; padding: 0 5px;display: flex;align-items: center;"
                      :style="{background:((item.approver === approver)&&(item.status === '1')) && pageType ==='approve'?'#fff':'#f5f5f5'}">
                      {{ item.departName }} {{ item.realname }} 意见:<a-input
                        :disabled="((item.approver === approver)&&(item.status === '1')) && pageType ==='approve'?false:true "
                        v-model="item.feedback" placeholder=""
                        style="width: 500px;border: none;background: none;"></a-input>
                    </div>
                    <a-list placeholder="请选择状态" :data-source="list"
                      style="font-size: 16px; width: 80px; margin-left: 5px; display: inline-block">
                      <!-- <a-list-item v-if="item.status == '0'" style="color: blue">待审核</a-list-item> -->
                      <a-list-item v-if="item.status == '1'" style="color: blue">审核中</a-list-item>
                      <a-list-item v-if="item.status == '2'" style="color: green">已同意</a-list-item>
                      <a-list-item v-if="item.status == '3'" style="color: red">已驳回</a-list-item>
                      <a-list-item v-if="item.status == '4'" style="color: gray">已撤销</a-list-item>
                    </a-list>
                  </div>
                  <div style="margin-left: 65px;margin-bottom: 10px;width: 730px;">
                    <j-upload v-model="item.ideaAttachment"
                      :disabled="((item.approver === approver)&&(item.status === '1')) && pageType ==='approve'?false:true"
                      :buttonVisible="!(((item.approver === approver)&&(item.status === '1')) && pageType ==='approve'?false:true )"></j-upload>
                  </div>
                </div>
              </block>
            </div>
          </a-form-model-item>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- <a-button @click="chexiao" type="primary" style="color: white; margin-left: 650px;">撤销</a-button> -->
    <!-- <a-button @click="submitForm1" type="primary" style="color: white; margin-left: 650px;">重新提交</a-button> -->
    <j-modal class="modal-privacy" :title="title" :visible="visible1" :disableScreenClick="true" okText="确定"
      cancelText="取消" @cancel="cancelPrivacy" @ok="confirmPrivacy">
      <textarea cols="70" rows="5" placeholder="请输入撤销原因"></textarea>

      <!-- <div style="font-size: 20px;width: 200px;height: 20px;margin: 0 auto;margin-top: 10px;">确定提交吗？</div> -->
    </j-modal>
    <wt-shishi-modal ref="modalForm"></wt-shishi-modal>

  </a-spin>
</template>

<script>
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  import {
    validateDuplicateValue
  } from '@/utils/util'
  import WtShishiModal from './WtShishiModal'

  export default {
    name: 'WtBrandForm',
    components: {
      WtShishiModal
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: true,
        required: false,
      },
    },
    data() {
      return {
        title: '撤销原因',
        model: {},
        visible1: false,
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          },
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
        },
        labelCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 2
          },
        },
        wrapperCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 22
          },
        },
        confirmLoading: false,
        validatorRules: {},
        levelOneOptions: [],
        // levelTwoOptions: [],
        // levelThreeOptions: [],
        treeData: [],
        treeData1: [],
        treeData2: [],

        list: [],
        // fileList: [],
        url: {
          add: '/wtBrand/add',
          edit: '/wtBrand/edit',
          queryById: '/wtBrand/queryById',
        },
        approver:'',
        pageType:'',
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model))
      if(!!window.localStorage.getItem("pro__Login_Userinfo")){
        let userInfo = JSON.parse(window.localStorage.getItem("pro__Login_Userinfo")).value;
        this.approver = userInfo.id;
      }
      getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
        if (res.success) {
          this.treeData = []
          let treeList = res.result
          for (let a = 0; a < treeList.length; a++) {
            let temp = treeList[a]
            temp.isLeaf = temp.leaf
            this.treeData.push(temp)
          }

          this.levelOneOptions = [...this.treeData].map((v) => {
            return {
              ...v,
              value: v.id,
              label: v.departName,
            }
          })
        }
      })
    },
    methods: {
      confirmPrivacy() {
        // console.log('同意了用户协议')
        // console.log(this.privacyDialogShow)l
        this.visible1 = false
        // console.log(this.privacyDialogShow)
      },
      cancelPrivacy() {
        // console.log('拒绝了用户协议')
        this.visible1 = false
      },
      submitForm1: function(record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "新增";
        // this.$refs.modalForm.disableSubmit = true;
      },
      loadTree(record) {
        var that = this
        getAction(`/countersign/wtCountersignServiceSettlement/queryByCountersignId?countersignId=${record.id}`).then(
          (res) => {
            if (res.success) {
              that.treeData1 = res.result
              // var treeList1 = res.result
              this.model = that.treeData1
              that.treeData2 = res.result.list
              this.list = that.treeData2
              // console.log('dwaq',treeList1);
              // for (let a = 0; a < treeList1.length; a++) {
              //   // console.log('ewq2');
              //   // let temp = treeList1[a]
              //   // temp.isLeaf = temp.leaf
              //   // that.treeData1.push(temp)
              // // console.log('dwaq1',that.treeData1);

              // }
              // that.model.id=that.treeData[0].id
            }
          }
        )
      },
      add() {
        this.edit(this.modelDefault)
      },
      edit(record,type) {
        // this.model = Object.assign({}, record)
        if(!!type){
          this.pageType = type;
        }
        this.visible = true
        this.loadTree(record)
      },
      chexiao() {
        this.visible1 = true
      },
      submitForm() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate((valid) => {
          if (valid) {
            that.confirmLoading = true
            let httpurl = ''
            let method = ''
            if (!this.model.id) {
              httpurl += this.url.add
              method = 'post'
            } else {
              httpurl += this.url.edit
              method = 'put'
            }
            httpAction(httpurl, this.model, method)
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.$emit('ok')
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.confirmLoading = false
              })
          }
        })
      },
    },
  }
</script>
<style scoped>
  .scroll-view {
    overflow: auto;
    overflow-y: scroll;
  }
</style>